$(function(){
	/*图片轮播*/
	ym.ajax({
		url:'/article/getScrollArticle',
		param:{
				scrollType:1
			},
		success:function(data){
			var $slider = $('#demo-slider-0');
			if(data.res ==1){
				for(var i=0;i<4;i++){
					$slider.flexslider('addSlide', '<li id="'+data.obj[i].articleId+'"><img src="'+data.obj[i].attachmentUrl+'">');
					$slider.flexslider('removeSlide', 0);
				}
			}
			else{console.log("数据获取失败！")}
		}
	});
	/*公告*/
	ym.ajax({
		url:'/article/getMenuArticle',
		param:{
				menuTagId :0
			},
		success:function(data){
			if(data.res ==1){
				if(data.obj.results.length > 0){
					console.log(data);
					$('.ggneirong').attr('id',data.obj.results[0].articleId);
					$('.ggneirong').html(data.obj.results[0].articleTitle);
				}else{
					$('.ggneirong').html("暂时无公告!");
					console.log("暂时无公告");
				}
				
			}else{console.log("数据获取失败！")}
		}
	});
	/*疫苗新闻*/
	ym.ajax({
		url:'/article/getMenuArticle',
		param:{
				menuTagId :5
			},
		success:function(data){
			
			console.log(data.obj);
			if(data.res ==1){
				$('.news').html("");
				if(data.obj.results != null && data.obj.results.length > 0){
					for(var i=0;i<3;i++){
						var html = "";
						var res = data.obj.results[i];
						html += '<li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left yimiaonews" id="'+res.articleId+'">'
									html +='<div class=" am-u-sm-7 am-list-main w65">'
									if(res.articleTitle.length > 13){
										html +='<h3 class="am-list-item-hd"><a href="javascript:void()" class="">'+res.articleTitle+'</a></h3>'
									}else{
										html +='<h3 class="am-list-item-hd" style="margin-bottom:2.5rem"><a href="javascript:void()" class="">'+res.articleTitle+'</a></h3>'
									}
									html +='<ul class="activity">'
										html +='<li><img src="../img/eyes.png"><span class="am-margin-left-xs">'+res.readNumber+'</span></li>'
										html +='<li><img src="../img/comments.png"><span class="am-margin-left-xs">'+res.replyCount+'</span></li>'
									html +='</ul>'
									html +='</div>'
									html +='<div class="am-u-sm-4 am-list-thumb">'
										html +='<a href="javascript:void()" class="">'
											html +='<img src="'+res.articleCoverUlr+'" alt="零星！"/>'
							      		html +='</a>'
							      	html +='</div>'
							       html +='</li>';	
						$('.news').append(html);
					}
					
				}else if(data.obj.results == null || data.obj.results.length == 0){
					var html = "";
					html = '<li class="am-text-center"><img style="width:100%" src="../img/no.jpg"></li>';
					$('.news').append(html);
				}
			}else{console.log("数据获取失败！")}
		}
	});
	
	/*疫苗新闻的点击事件*/
	$('body').on('click','.yimiaonews',function(){
		var id = $(this).attr('id');
		ym.ajax({
			url:'/article/updateArticleReadNumber',
			type:'post',
			param:{ articleId:id},
			success:function(data){
				if(data.res ==1){
					console.log("数据获取成功跳转页面！")
				}else{console.log("数据获取失败！")}
				window.location.href='yimiaoxinwenXq.html?articleId='+id;
			}
		});
	})
	/*点击公告*/
	$('.ggneirong').on('click',function(){
		var id = $(this).attr('id');
		if(id == undefined){
			
		}else{
			ym.ajax({
				url:'/article/updateArticleReadNumber',
				type:'post',
				param:{ articleId:id},
				success:function(data){
					if(data.res ==1){
						console.log("数据获取成功跳转页面！")
					}else{console.log("数据获取失败！")}
					window.location.href='yimiaoxinwenXq.html?articleId='+id;
				}
			});
		}
		
		
	})
	/*轮播图点击事件*/
	$('body').on('click','.am-slides>li',function(){
		var id = $(this).attr('id');
		ym.ajax({
			url:'/article/updateArticleReadNumber',
			type:'post',
			param:{ articleId:id},
			success:function(data){
				if(data.res ==1){
					console.log("数据获取成功跳转页面！")
				}else{console.log("数据获取失败！")}
				window.location.href='yimiaoxinwenXq.html?articleId='+id;
			}
		});
	})

})
